<template>
	<view class="body">
		<paper-popop :show="show" @hide="hidepopup" @add="addfriend" @clear="clear"></paper-popop>
		<!-- 小纸条列表 -->
		<block v-for="(item,index) in list" :key="index">

			<paper-list :item="item" :index="index"></paper-list>
		</block>

		<!-- 上拉加载中 -->
		<load-more :loadtext="loadtext"></load-more>
	</view>
</template>

<script>
	
	import paperPopop from "../../components/paper/paper-popop.vue";
	import paperList from "../../components/paper/paper-list.vue";
	import uniBadge from "../../components/uni-badge/uni-badge.vue";
	import loadMore from "../../components/common/load-more.vue";
	export default {
		components: {
			uniBadge,
			paperList,
			loadMore,
			paperPopop
		},
		data() {
			return {
				show:false,
				loadtext: "上拉加载更多",
				list: [{
						userpic: "../../static/srcc/d1.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/srcc/1.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/srcc/2.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 85
					},
					{
						userpic: "../../static/srcc/d1.jpg.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 88
					},
					{
						userpic: "../../static/srcc/d1.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/srcc/1.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/srcc/2.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 85
					},
					{
						userpic: "../../static/srcc/d1.jpg.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 88
					}, {
						userpic: "../../static/srcc/d1.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/srcc/1.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/srcc/2.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 85
					},
					{
						userpic: "../../static/srcc/d1.jpg.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 88
					}
				]
			}
		},
		//监听下拉刷新
		onPullDownRefresh() {
			this.xialashuaxin()
		},
		//监听页面滚动事件
		onReachBottom() {
			this.loadmore();
		},
// 监听导航按钮点击事件
		onNavigationBarButtonTap(e) {
			switch (e.index){
				case 0:
				uni.navigateTo({
					url:'../user-list/user-list'
				})
				this.hidepopup();
					break;
				case 1:
				this.showpopup();
					break;
			}
			},
		methods: {
			addfriend(){
							console.log("加糗友");
							this.hidepopup();
						},
						clear(){
							console.log("清除缓存");
							this.hidepopup();
						},
						hidepopup(){
							this.show=false;
						},
						showpopup(){
							this.show=true;
						},
			//上拉加载

			loadmore() {
				//如果目前全等于加载更多我们就给他这个事件，不然就return
				if (this.loadtext != "上拉加载更多") {
					return;
				}
				//修改状态
				this.loadtext = "加载中...";
				//获取数据
				setTimeout(() => {
					//获取完成
					let obj = {


						userpic: "../../static/srcc/touxiang.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 85


					};


					this.list.push(obj);
					this.loadtext = "上拉加载更多"
				}, 1000);


			},
			// 获取数据模拟
			xialashuaxin() {

				setTimeout(() => {
					// 服务器数据
					let arr = [{
							userpic: "../../static/srcc/d1.jpg",
							username: "Vincent",
							time: "10:21",
							data: "我是信息",
							noreadnum: 88
						},
						{
							userpic: "../../static/srcc/1.jpg",
							username: "天空",
							time: "10:21",
							data: "我是信息",
							noreadnum: 0
						},
						{
							userpic: "../../static/srcc/2.jpg",
							username: "昵称",
							time: "10:21",
							data: "我是信息",
							noreadnum: 99
						},
						{
							userpic: "../../static/srcc/d1.jpg.jpg",
							username: "代码",
							time: "10:21",
							data: "我是信息",
							noreadnum: 66
						}
					]
					// 赋值
					this.list = arr;
					// 停止刷新
					uni.stopPullDownRefresh();

				}, 3000);

			}
		}
	}
</script>

<style>
	.body {
		padding: 0 20upx;
	}
	.papar-left-popup-mask{
		position: fixed;
		right: 0;
		left: 0;
		top: 0;
		bottom: 0;
		z-index: 1999;
	}
	.papar-left-popup{
		position: fixed;
		right: 0;
		top: 90upx;
		background: #FFFFFF;
		z-index: 2000;
		width: 55%;
		box-shadow: 1upx 1upx 20upx 2upx #CCCCCC;
	}
	.papar-left-popup>view{
		padding: 20upx;
		font-size: 35upx;
	}
	.papar-left-popup>view>view{
		margin-right: 10upx;
		font-weight: bold;
	}
	.papar-left-popup-h{
		background: #EEEEEE;
	}
</style>
